﻿namespace OP10.ViewModels
{
    public class ST04CyManagerViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public ST04CyManagerViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;

            InitParam();
        }
        private void InitParam()
        {
            //气缸感应器延时参数初始化赋值
            CylinderDelay.DelayTime01 = ST04WiredClampCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime02 = ST04ShiftCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime03 = ST04PushMaterialUpDownCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime04 = ST04ElectrodeUpDownCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime05 = ST04StationBreakAwayCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime06 = ST04TrashBlowCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime07 = ST04TrashInhaleCy.cylinderPCToPLC_Global.tBackTime;

            CylinderDelay.DelayTime08 = ST04WiredClampCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime09 = ST04ShiftCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime10 = ST04PushMaterialUpDownCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime11 = ST04ElectrodeUpDownCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime12 = ST04StationBreakAwayCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime13 = ST04TrashBlowCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime14 = ST04TrashInhaleCy.cylinderPCToPLC_Global.tGoTime;

            checkModel.IsQGOriginCheck01 = ST04WiredClampCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck02 = ST04ShiftCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck03 = ST04PushMaterialUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck04 = ST04ElectrodeUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck05 = ST04StationBreakAwayCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck06 = ST04TrashBlowCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck07 = ST04TrashInhaleCy.cylinderPCToPLC_Global.bOrgSenByPass;


            checkModel.IsQGWorkCheck01 = ST04WiredClampCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck02 = ST04ShiftCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck03 = ST04PushMaterialUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck04 = ST04ElectrodeUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck05 = ST04StationBreakAwayCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck06 = ST04TrashBlowCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck07 = ST04TrashInhaleCy.cylinderPCToPLC_Global.bWorkSenByPass;
        }

        #region 事件
        private DelegateCommand _GoBackCommand;

        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));

        void ExecuteGoBackCommand()
        {
            NavigationParameters param = new NavigationParameters();
            param.Add("StationName", "ST04");
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST04View, param);
        }



        /// <summary>
        /// 气缸屏蔽
        /// </summary>
        private DelegateCommand<string> _CylinderPinBiCommand;
        public DelegateCommand<string> CylinderPinBiCommand =>
            _CylinderPinBiCommand ?? (_CylinderPinBiCommand = new DelegateCommand<string>(ExecuteCylinderPinBiCommand));

        void ExecuteCylinderPinBiCommand(string p)
        {
            switch (p)
            {
                case "ST4桥丝夹持原点":
                    ST04WiredClampCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST4吸枪移位原点":
                    ST04ShiftCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST4压料上下气缸原点":
                    ST04PushMaterialUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST4电极上下气缸原点":
                    ST04ElectrodeUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST4工站脱离原点":
                    ST04StationBreakAwayCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST4废料吹原点":
                    ST04TrashBlowCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST4废料吸原点":
                    ST04TrashInhaleCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST4桥丝夹持动点":
                    ST04WiredClampCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST4吸枪移位动点":
                    ST04ShiftCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST4压料上下气缸动点":
                    ST04PushMaterialUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST4电极上下气缸动点":
                    ST04ElectrodeUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST4工站脱离动点":
                    ST04StationBreakAwayCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST4废料吹动点":
                    ST04TrashBlowCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST4废料吸动点":
                    ST04TrashInhaleCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 气缸解除屏蔽
        /// </summary>
        private DelegateCommand<string> _CylinderUnPinBiCommand;
        public DelegateCommand<string> CylinderUnPinBiCommand =>
            _CylinderUnPinBiCommand ?? (_CylinderUnPinBiCommand = new DelegateCommand<string>(ExecuteCylinderUnPinBiCommand));

        void ExecuteCylinderUnPinBiCommand(string p)
        {
            switch (p)
            {
                case "ST4桥丝夹持原点":
                    ST04WiredClampCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST4吸枪移位原点":
                    ST04ShiftCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST4压料上下气缸原点":
                    ST04PushMaterialUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST4电极上下气缸原点":
                    ST04ElectrodeUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST4工站脱离原点":
                    ST04StationBreakAwayCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST4废料吹原点":
                    ST04TrashBlowCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST4废料吸原点":
                    ST04TrashInhaleCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST4桥丝夹持动点":
                    ST04WiredClampCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST4吸枪移位动点":
                    ST04ShiftCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST4压料上下气缸动点":
                    ST04PushMaterialUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST4电极上下气缸动点":
                    ST04ElectrodeUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST4工站脱离动点":
                    ST04StationBreakAwayCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST4废料吹动点":
                    ST04TrashBlowCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST4废料吸动点":
                    ST04TrashInhaleCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                default:
                    break;
            }
        }


        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));

        void ExecuteTextChangeCommand(string p)
        {
            switch (p)
            {

                case "DelayTime01":
                    ST04WiredClampCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime01;
                    break;
                case "DelayTime02":
                    ST04ShiftCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime02;
                    break;
                case "DelayTime03":
                    ST04PushMaterialUpDownCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime03;
                    break;
                case "DelayTime04":
                    ST04ElectrodeUpDownCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime04;
                    break;
                case "DelayTime05":
                    ST04StationBreakAwayCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime05;
                    break;
                case "DelayTime06":
                    ST04TrashBlowCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime06;
                    break;
                case "DelayTime07":
                    ST04TrashInhaleCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime07;
                    break;
                case "DelayTime08":
                    ST04WiredClampCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime08;
                    break;
                case "DelayTime09":
                    ST04ShiftCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime09;
                    break;
                case "DelayTime10":
                    ST04PushMaterialUpDownCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime10;
                    break;
                case "DelayTime11":
                    ST04ElectrodeUpDownCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime11;
                    break;
                case "DelayTime12":
                    ST04StationBreakAwayCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime12;
                    break;
                case "DelayTime13":
                    ST04TrashBlowCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime13;
                    break;
                case "DelayTime14":
                    ST04TrashInhaleCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime14;
                    break;
                default:
                    break;
            }
        }
        #endregion


        #region 属性  

        private CylinderDelayModel _cylinderDelay;
        public CylinderDelayModel CylinderDelay
        {
            get { return _cylinderDelay ?? (_cylinderDelay = new CylinderDelayModel()); }
            set { SetProperty(ref _cylinderDelay, value); }
        }

        private CylinderSensorCheckModel _checkModel;
        public CylinderSensorCheckModel checkModel
        {
            get { return _checkModel ?? (_checkModel = new CylinderSensorCheckModel()); }
            set { SetProperty(ref _checkModel, value); }
        }
        #endregion
    }
}
